package protobuf.Serialization;

import myClient.session.ClientSession;
import protobuf.protoClass.ProtoMsg;

public class HeartBeatMsgConverter extends BaseConverter {

    /**
     * {@link ProtoMsg.Message} 中 MessageHeartBeat 字段
     */
    public HeartBeatMsgConverter(ClientSession session) {
        super(ProtoMsg.HeadType.HEART_BEAT, session);
    }

    /**
     * 静态方法
     *
     * @param session session
     * @return 心跳信息
     */
    public static ProtoMsg.Message build(ClientSession session) {
        return new HeartBeatMsgConverter(session).build();
    }

    /**
     * 设置 ProtoMsg.Message第 9个字段：MessageHeartBeat ，
     * 并调用 build()方法，创建 ProtoMsg.Message
     */
    public ProtoMsg.Message build() {
        //构建 ProtoMsg.MessageHeartBeat
        ProtoMsg.MessageHeartBeat.Builder heatBeatBuilder =
                ProtoMsg.MessageHeartBeat.newBuilder()
                        .setSeq(0)
                        .setUid(super.session.getUserAttribute().getUid())
                        .setJson("{\"from\":\"client\"}");

        //将信息序列号设置为 -1
        return get_ProtoMsg_Message_Builder_withThreeFields(-1)  // ProtoMsg.Message前三个字段
                .setHeartBeat(heatBeatBuilder)  //ProtoMsg.Message第 9个字段：MessageHeartBeat 心跳
                .build();
    }

}
